from haystack import indexes

from .models import Doctoc


class DoctocIndex(indexes.SearchIndex, indexes.Indexable):
    """
    doctoc索引数据模型类
    """
    # document主要查询字段
    text = indexes.CharField(document=True, use_template=True)

    id = indexes.IntegerField(model_attr='id')
    name = indexes.CharField(model_attr='name')
    hospitalname = indexes.CharField(model_attr='hospitalname')
    subject = indexes.CharField(model_attr='subject')
    hospital = indexes.IntegerField(model_attr='hospital')

    def get_model(self):
        """返回建立索引的模型类"""
        return Doctoc

    def index_queryset(self, using=None):
        """返回要建立索引的数据查询集"""
        return self.get_model().objects.all()
